package com.bat.conf;

import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

/**
 * @Description: 过滤feign接口
 * @Author: zpf
 * @Date: 2019/11/5 下午4:00
 */
@Configuration
public class WebMvcRegistrationAdpater implements WebMvcRegistrations {
    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        return new MyRequestMappingHandlerMapping();
    }

    static class MyRequestMappingHandlerMapping extends RequestMappingHandlerMapping {

        @Override
        protected boolean isHandler(Class<?> beanType) {

            // 原来逻辑:
            /*
            return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
                    AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class));
             */

            //去掉RequestMapping
            return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) || (
                AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class) && !beanType.isInterface()));
        }
    }
}
